﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace _395_2d
{
    class NPC : Ship
    {
        private Vector2 Velocity;

        public NPC(SpriteManager sm, string t, IList<MountedWeapon> mw, int h, Vector2 p, Vector2 s, Vector2 v, double spawnTime)
        {
            Texture = t;
            Health = h;
            Velocity = v;

            MountedWeapons = new List<MountedWeapon>( mw );
            LastShot = new List<double>();
            foreach (MountedWeapon m in MountedWeapons)
            {
                LastShot.Add(spawnTime + m.WarmUpTime);
            }

            bounds = new BoundingBox(p, s);
            SM = sm;
        }

        public override void Update(GameTime gt)
        {
            bounds.topLeft += Velocity * (float)gt.ElapsedGameTime.TotalSeconds;
        }

        public override void shoot(GameTime gt)
        {
            for ( int i = 0; i < MountedWeapons.Count; i++ )
            {
                Weapon w = (Weapon)Content.Weapons[MountedWeapons[i].Weapon];

                if (gt.TotalGameTime.TotalSeconds > MountedWeapons[i].WarmUpTime && 
                    w.RateOfFire > 0 && gt.TotalGameTime.TotalSeconds - LastShot[i] > w.RateOfFire)
                {
                    SM.AddEnemyProjectile(new Bullet(bounds.topLeft + MountedWeapons[i].Location, MountedWeapons[i].Aim, w.ProjectileDamage, w.ProjectileTexture));
                    LastShot[i] = gt.TotalGameTime.TotalSeconds;
                }
            }
        }
    }
}
